Hi to all!!!! I Am Arpit Vijay Vergiya.
On this Blog i tried to share about Java.
I hope this blog will help you to learn many new things in java.
Keep visiting!!!
Keep sharing

Showing posts with label Java tutorials. Show all posts
Showing posts with label Java tutorials. Show all posts
by · No comments:

Matrix multiplication


import java.util.Scanner;
class MatrixMul{
		public static void main(String args[])
		{
				int a[][]= new int[3][3];
				int b[][]= new int[3][3];
				int c[][]=new int[3][3];
				int i,j,k;
				
				Scanner sc = new Scanner(System.in);
				System.out.println("enter Element 9 of 1st String");
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								a[i][j]=sc.nextInt();
						}
				}
				
				System.out.println("enter Element 9 of 2nd String");
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								b[i][j]=sc.nextInt();
						}
				}
				
				System.out.println("Matrix A\tMatrix B");
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								System.out.print(a[i][j]+" ");
						}
						
						System.out.print("\t\t");
						
						for(k=0;k<3;k++)
						{
								System.out.print(b[i][k]+" ");
						}
						System.out.println();
				}
				
				//logic for multiply
				
				int mul=0;
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								
								for(k=0;k<3;k++)
								{
										mul+= a[i][j]*b[j][k];
								}
								
								c[i][j]=mul;
								mul=0;
						}
			
				}
				
				System.out.println("Result is:");
				for( i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								System.out.print(c[i][j]+" ");
						}
						
						System.out.println(" ");
				}
				
		}
}

Read More
by · No comments:

Arrange String character wise

import java.util.Scanner;
class StringCharSort{
		
		public static void main(String args[])
		{
				Scanner sc = new Scanner(System.in);
				System.out.println("Enter a String:");
				String str = sc.nextLine();
				char ch[] = str.toCharArray();
				for(int i=0;i	for(int j=1;j
						{
								if(ch[j-1]>ch[j])
								{
										char temp = ch[j-1];
										ch[j-1]=ch[j];
										ch[j]=temp;
								}
						
						}
						
				}
				for(char c :ch)
							{
									System.out.print(c);
							}
				
		}
		
}


Read More
by · No comments:

How to check given String is palindrom or not in java

String is palindrom or not


import java.util.Scanner;
class StringPalindrom{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter a line");
    String str = sc.nextLine();
    String str1="";
    char ch[] = str.toCharArray();
    for(int i=ch.length-1;i>=0;i--)
    {
      str1+=ch[i];
    }
     if(str.equals(str1))
      System.out.println("Palindrom");
     else
      System.out.println("Not palindrom");
    
    
  }
}






Read More
by · No comments:

Differences Between C , C++, and Java

Differences Between C , C++, and Java

Table Comparing C, C++ and Java:

This table is a summary of the differences found in the article.
Feature
C
C++
Java
Programming Approach
Procedural Programming Language
Procedural, OOP, Generic Programming languages
OOP, Generic Programming languages.
Compiled Source Code
Executable in  Native Code
Executable in Native Code
Compiled into Java byte code
Memory management
Manual Done,
Manual Done,
Managed, using a garbage collector
Pointers
Yes, very commonly used.
Yes, very commonly used, but some form of references available too.
No pointers; references are used instead.
Preprocessor
Yes
Yes
No
String Type
Character arrays
Character arrays, objects
Objects
Complex Data Types
Structures, unions
Structures, unions, classes
Classes
Inheritance
N/A
Multiple class inheritance
Single class inheritance, multiple interface implementation
Operator Overloading
N/A
Yes
No
Automatic coercions
(Conversion)
Yes, with warnings if loss could occur
Yes, with warnings if loss could occur
Not at all if loss could occur; must cast explicitly
Variadic Parameters
Yes
Yes
No
Goto Statement
Yes
Yes
No

 

Read More
by · No comments:

Age Calculater in java

Hiii Guys i was reading Date and Calendar class in java. With these two classes we can perform on date.Like we can get Date of system.
And we can calculate difference in two Dates.
We can get the year month and date of user given date.
so i got an idea why can not i write source code in which we can calculate age of a person by given his birth date or current date of system.

Here the source code for Age Calculator:-




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.event.*;
public class AgeCal1 extends JFrame implements ActionListener
{
    JList jdate,jmonth,jyear;
    JPanel jp,jp1,jp2;
    JScrollPane jsp1,jsp2,jsp3;
    JButton jb;
    JMenuBar jmb;
    JMenu file,help;
    JMenuItem exit,aboutUs;   
    public AgeCal1()
    {
      
    setTitle("Age Calculator");
        setSize(400,450);
        setLayout(null);
    getContentPane().setBackground(Color.PINK);
   
        jmb = new JMenuBar();
        file = new JMenu("File");
        file.setMnemonic(KeyEvent.VK_F);
        help = new JMenu("Help");
        help.setMnemonic(KeyEvent.VK_H);
        exit = new JMenuItem("Exit");
        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK));
        exit.addActionListener(this);
        file.add(exit);
        aboutUs = new JMenuItem("About Us");
        aboutUs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,ActionEvent.CTRL_MASK));
        aboutUs.addActionListener(this);
        help.add(aboutUs);
        jmb.add(file);
        jmb.add(help);
        setJMenuBar(jmb);
    addWindowListener(new MyWindowListener(this));
        Vector<Integer>date=new Vector<Integer>();
        {
            for(int i=1;i<=31;i++)
            {
                date.add(i);
            }
        }
        jdate = new JList(date);
        jdate.setVisibleRowCount(5);
        jdate.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Vector<Integer> mon = new Vector<Integer>();
       
            for(int i=1;i<=12;i++)
            {
            mon.add(i);   
            }
       
        jmonth = new JList(mon);
        jmonth.setVisibleRowCount(4);
        jmonth.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Vector<Integer>year = new Vector<Integer>();
        for(int i=1950;i<2050;i++)
        {
            year.add(i);
        }
        jyear = new JList(year);
       
        jyear.setVisibleRowCount(10);
        jyear.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jp = new JPanel();
        jp.setBorder(BorderFactory.createTitledBorder("Select date"));
       
        jp1=new JPanel();
        jp1.setBorder(BorderFactory.createTitledBorder("Select Month"));
       
        jp2 = new JPanel();
        jp2.setBorder(BorderFactory.createTitledBorder("Select Year"));
        jsp1 = new JScrollPane(jdate);
        jsp2 = new JScrollPane(jmonth);
        jsp3 = new JScrollPane(jyear);
       
        jp.add(jsp1);
        jp.setBackground(Color.orange);
        jp1.add(jsp2);
        jp2.add(jsp3);
        jp.setBounds(10,100,100,200);
        jp1.setBounds(130,100,100,150);
        jp2.setBounds(250,100,100,220);
        add(jp);
        add(jp1);
        add(jp2);
        jb = new JButton("Calculate");
        jb.setBounds(100,350,100,40);
        add(jb);
        jb.addActionListener(this);
        setVisible(true);
       
    }
    @Override
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==jb)
        {
        try
        {

    int userDate = (Integer)jdate.getSelectedValue();
   
    int userMonth = (Integer)jmonth.getSelectedValue();
   
    int userYear = (Integer)jyear.getSelectedValue();

    Calendar bday = Calendar.getInstance();
    bday.set(userYear,userMonth,userDate);
    Calendar today = Calendar.getInstance();
   
    if((today.after(bday)))
    {
        int curDate = today.get(Calendar.DATE);
        int curMonth = today.get(Calendar.MONTH);
        int curYear = today.get(Calendar.YEAR);
        int day = userDate-curDate;
        if(day>0)
        {
            day=day;
        }
        else
        {
            day=day+(2*(-day));
        }
   
        int month = userMonth-curMonth;
        if(month>0){
        month=month;
        }
        else
        {
            month= month+(2*(-month));
        }
       
        int year = userYear-curYear;
        if(year>0)
        {
            year=year;
        }
        else
        {
            year =year+(2*(-year));
        }
       
        JOptionPane.showMessageDialog(this,"You Are:"+year+" Year"+" "+month+
            "Month"+day+" "+"Days Old..","AgeCal by Arpit",JOptionPane.INFORMATION_MESSAGE);
    }
    else
    {
        JOptionPane.showMessageDialog(this,"Bawali pooch tu to paida nhi hua","AgeCal",JOptionPane.ERROR_MESSAGE);
    }
       
        }
        catch(Exception e)
        {
            if(jdate.getSelectedValue()==null)
    {
        JOptionPane.showMessageDialog(this,"Please select Your Birth Date???","AgeCal v1.0",JOptionPane.ERROR_MESSAGE);
    }
    else if(jmonth.getSelectedValue()==null)
    {
    JOptionPane.showMessageDialog(this,"Please select Your Birth Month???","AgeCal v1.0",JOptionPane.ERROR_MESSAGE);
    }
   
    else    if(jyear.getSelectedValue()==null)
    {
        JOptionPane.showMessageDialog(this,"Please select Your Birth Year????","AgeCal v1.0",JOptionPane.ERROR_MESSAGE);
    }
   
   
        }
       
        }
        if(ae.getSource()==exit)
        {
            Sysetm.exit(0);
        }
        if(ae.getSource()==aboutUs)
        {
            JOptionPane.showMessageDialog(this,"Developed By Arpit Vijay"+"\n"+"Contact:-Vijayarpit.vijay@gmail.com","Agecal v1.0",JOptionPane.INFORMATION_MESSAGE);
        }
    }
   
    public static void main(String...s)
    {
        new AgeCal1();
    }
}


 class MyWindowListener extends WindowAdapter
 {
     AgeCal1 close;
     public MyWindowListener(AgeCal1 ac)
     {
         close =ac;
     }
     @Override
     public void windowClosing(WindowEvent we)
     {
         int x = JOptionPane.showConfirmDialog(close,"Really do you Want to exit???","AgeCal v1.0",JOptionPane.YES_NO_OPTION);
         if(x==JOptionPane.YES_OPTION)
         {
             close.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         }
         if(x==JOptionPane.NO_OPTION)
         {
             close.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         }
     }
 }





Thanx Guys Dont forget to share and like.
Soon i am going to upload its .Exe so you can easily Run it on windows
Read More
by · No comments:

Features of java

Features of java 

Java is so much popular because of its features.

These are:-

1. Simple, easy and familiar:  

Java is easy to learn and familiar because java syntax is just like c++.
It is simple because:
a) it does not use header files.
b) eliminated the use of pointer and operator overloading.
- See more at: http://javawithease.com/java-features/#sthash.mMzM5XrM.dpuf

1. Simple, easy and familiar:

Java is easy to learn and familiar because java syntax is just like c.
It is simple because:
a) it does not use header files.
b) eliminated the use of pointer and operator overloading.
 

 2. Platform Independent: 
Write once, run anywhere (WORA).


3.Object-Oriented:

Java is Object oriented throughout language- that mean no coding outside of

class definitions,  including main().

Basic concepts of OOPs are:

  •     Object
  •     Class
  •     Inheritance
  •     Polymorphism
  •     Abstraction
  •     Encapsulation

4. Robust:

 Robust  means inbuilt capabilities to handle errors/exceptions.
 Java is robust because of  following:

1. Built-in Exception handling.

2. Strong type checking i.e. all data must be declared an explicit type.

3. Local variables must be initialized.

4. Automatic garbage collection.

5. First checks the reliability of the code before Execution etc.


5. Secure:  
Java is secure because it provides:

1. access restrictions with the help of access modifiers (public, private etc).

2. byte codes verification – checks classes after loading.

Class loader – confines objects to unique namespaces.

Bytecode Verifier- checks the code fragments for illegal code that can violate access right to objects.

Security manager – determines what resources a class can access such as reading and writing to the local disk.


6. Distributed:

Java provides the network facility. i.e. programs can be access remotely from any machine on the network rather than writing program on the local machine. HTTP and FTP protocols are developed in java.
 

7. Compiled and interpreted:

Java code is translated into byte code after compilation and the byte code is interpreted by JVM (Java Virtual Machine). This two steps process allows for extensive code checking and also increase security.
 

8. Portable:

Means able to be easily carried or moved. Write once, run anywhere (WORA) feature makes it portable.
 

9. Architecture-Neutral:

Java code is translated into byte code after compilation which is independent of  any computer architecture, it needs only JVM (Java Virtual Machine) to execute.
 

10. High performance:

JVM  can execute byte codes (highly optimized) very fast with the help of  Just in time (JIT) compilation technique.
11. Re-usability of code:

Java provides the code reusability With the Help of Inheritance.
 

12. Multithreading:

Java provides multitasking facility with the help of lightweight processes called threads.
 

13. Dynamic:

Java have the capability of linking dynamic new classes, methods and objects.

Read More
by · No comments:

Java History


Green Project


January, 1991

Project named “Green Project” was started. Green project’s goal was to support home consumer devices. Consumer devices to be made intelliegent so they can interact with each other and they can be controlled via a remote. Bill Joy, James Gosling, Mike Sheradin, Patrick Naughton were the key members of the Green Project.

Oak


         February, 1991


James Gosling was the software lead and architect. His initial objective was to find a suitable language for Green Project. He chose C++ and wrote extensions wherever there were gaps. Then the features were not sufficient for the project needs and creating a new language was the next move. He started working on the new language and named it as “Oak”, there was an Oak tree outside his office window.



Hardware Prototype


April, 1991

SPARCstation 10’s architect Ed Frank joins Green project to lead the hardware work. Objective was to develop a hardware prototype and demonstrate the capabilities. The project was code named star-seven (*7). Team members of star 7 project were Craig Forrest, Al Frazier, Ed Frank, James Gosling, Patrick Naughton, Joe Parlang, Jon Payne, Mike Sheridan, Chris Warth.


Interpreter

June, 1991
James Gosling works on Oak interpreter


1992

Java Named

March, 1992

Oak was name of another already existing language and so a new name was chosen and it was Java. It was inspired by coffee.



Star-seven Prototype

September, 1992

Star-seven (*7) working prototype with a GUI was completed and demonstrated. At this time Green project has created a new language, an operating system, a hardware platform and an interface. Below is the demo of PDA like star 7 prototype and demo was given by James Gosling himself.



FirstPerson

November, 1992

Green project was incorporated as a separate entity with a name FirstPerson as a subsidiary of Sun Microsystems.

1993

TV Set-top Box

February, 1993

FirstPerson attempts to bag order from Time-Warner for a TV set-top box interactive system. By this time, green project was not proving successful and Time-Warner order was also lost. From home consumer electronics the focus was shifted to TV and set-top box related platform.

Application Development for Platform

September, 1993

Arthur Van Hoff joins the team to work on application development for the interactive platform.

1994

Liveoak

June, 1994

Even TV interactive market was not fruitful for FirstPerson and it was closed. Employees absorbed into Sun. Liveoak project started, aim was to create an operating system by using Oak.

Web Browser Era

July, 1994

Patrick Naughton creates a web browser and uses Java in it. Liveoak project modified to make Oak for Internet.

HotJava

September, 1994

Naughton and Jonatha Payne starts working on a Java based web browser named HotJava and this project gets wider acceptance from the management and progresses.

Java Compiler

October, 1994

Java compiler was written by Van Hoff using Java, previously it was written in C by James Gosling.

1995

Formal Launch

May, 1995

At SunWorld conference Java and HotJava was formally introduced by Sun.


Netscape Support

June, 1995

In a major breakthrough, Netscape supports Java in its browser.

HotJava

September, 1995

First Java developer conference held by Sun at New York.

Oracle Support

October, 1995

Oracle includes a Java compatible browser in its launch of WWW WebSystem.

Microsoft Support

December, 1995

In a first signal for wider industry acceptance, Microsoft supports Java in IE.

 

1996

1.0

January, 1996

JDK 1.0 released.

1997

1.1

February, 1997

JDK 1.1 released. Key features were JDBC, RMI, Inner Classes.

1998

1.2

December, 1998

JDK 1.2 code named Playgroud released. This version is mostly called Java 2 and was the most popular release which witnessed major conversions. Major features were collections framework, JIT compiler, policy tool, Java foundation classes, Java 2D class libraries, major enhancement in JDBC.

2000

1.3

May, 2000

JDK 1.3 code named Kestrel released.

2002

1.4

February, 2002

J2SE 1.4 code named Merlin released. Major features were XML Processing, Java Print, Logging, JDBC 3.0, Assertions, Regular Expressions

 


 

2004

 

5.0

September, 2004

J2SE 5.0 code named Tiger released. Major features were Generics, Autoboxing, Annotations, Instrumentation.

2006

Java/Jdk (Half) Open Sourced

November, 2006

Java was announced to be open source and it was controversial. The way the license was designed contradicted the general open source term. May be we should call it half-sourced.

6.0

December, 2006

Java SE 6 code named Mustang released. Major features were Scripting Language Support, JDBC 4.0, Java Compiler API, Integrated Web Services.

2010

Oracle Buys Sun

January, 2010

Oracle buys Sun and its products. Now Java is in the hands of Oracle.

No Support for Java in Future – Apple

October, 2010

Steve Jobs says, Apple will not support Java in future.

2011

7.0

July, 2011

Java SE 7 code named Dolphin released. This release was done after 5 long years and only this release has taken this much duration. Major features were dynamic language support, Java nio Package, multiple exception handling, try with resources and lots of minor enhancements.

2014

8

18 March, 2014

Java SE 8 was released. This is one of the major release in Java in its history. Major features were Lambda Expressions, Pipelines and Streams, Date and Time API , Default Methods, Type Annotations, Nashhorn JavaScript Engine, Concurrent Accumulators, Parallel operations, PermGen Space Removed, TLS SNI.





 
Read More
by · No comments:

Programming language overview

Programming language overview

As we are going to start learning Java, which is a programming language. So, let us have a brief look at programming language first.

What is language?
A way of communication is known as language. e.g. Hindi, English etc.

What is a Program?
A set of instructions which is used to perform a specific task.

What is a Programming Language?  
An artificial language used to write programs which can be translated into machine language and executed by computer with the help of some special software.
 

What is a Platform?  
Dictionary meaning: A raised level surface on which things can stand.
In programming: Hardware or software on which a program can execute/run.e.g. – c, c++, Java etc.

Programming language overview

As we are going to start learning Java, which is a programming language. So, let us have a brief look at programming language first.

What is language?

A way of communication is known as language. e.g. Hindi, English etc.

What is a Program?

A set of instructions which is used to perform a specific task.

What is a Programming Language?   

An artificial language used to write programs which can be translated into machine language and executed by computer with the help of some special software.

What is a Platform?   

Dictionary meaning: A raised level surface on which things can stand.
In programming: Hardware or software on which a program can execute/run.
e.g. – c, c++, Java etc.
- See more at: http://javawithease.com/programing-language-overview/#sthash.asmxOycF.dpuf
Read More